PROGRAM RANDOM2;{Straight Selection sort as the sort method}
CONST MAXSIZE=500;
TYPE INDEX=0..MAXSIZE;
VAR SEED:REAL;
DIDSWAP:BOOLEAN;
TIMEDIFF,HITIME,LO1TIME,LO2TIME,X,Y:INTEGER;
SCALAR:ARRAY[1..MAXSIZE] OF INTEGER;

PROCEDURE SELECTSORT;
VAR I,J,K:INDEX;
        X:INTEGER;
BEGIN
   FOR I:=1 TO MAXSIZE-1 DO
   BEGIN
      K:=I;
      X:=SCALAR[I];
      FOR J:=I+1 TO MAXSIZE DO
         IF SCALAR[J]<X THEN
            BEGIN
            K:=J;
            X:=SCALAR[J];
            END;
         SCALAR[K]:=SCALAR[I];
         SCALAR[I]:=X;
   END;
END;

FUNCTION RANDOM:INTEGER;
BEGIN
SEED:=SEED*27.182813+31.415917;
SEED:=SEED-TRUNC(SEED);
IF SEED<0 THEN
   SEED:=-SEED;
RANDOM:=TRUNC(SEED*50+1);
END;

BEGIN
TIME(HITIME,LO1TIME);
SEED:=1.23456789;
FOR X:=1 TO MAXSIZE DO
   SCALAR[X]:=RANDOM;
FOR Y:=1 TO MAXSIZE DO
   WRITE(SCALAR[Y]:4);
SELECTSORT;
FOR Y:=1 TO MAXSIZE DO
   WRITE(SCALAR[Y]:4);
TIME(HITIME,LO2TIME);
TIMEDIFF:=LO2TIME-LO1TIME;
IF TIMEDIFF<0 THEN
   TIMEDIFF:=TIMEDIFF+32767;
WRITELN(TIMEDIFF DIV 60,'.',(100*(TIMEDIFF MOD 60) DIV 60),' seconds');
END.
